{include /common/header}
<script>
    var M={};
    $(function() {
        M.del = function(id){
            if (confirm('确定删除吗？')) {
                $.ajax({
                    url: '{:\mylib\Route::buildUrl('/admin/content/del')}',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        id:id
                    },
                    success:function(res){
                        if (res.code) {
                            location.reload();
                        }else{
                            alert(res.message);
                        }
                    }
                });
            }
        }
    });
</script>
<div class="title">{$channel.title}</div>
<p>
    <a href="{:\mylib\Route::buildUrl('/admin/content/add')}?channel_id={$channel_id}" class="btn btn-primary">添加内容</a>
</p>
<div class="table-responsive">
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>#</th>
                <th>标题</th>
                <th>属性</th>
                {foreach $fields as $v}
                <th>{$v.title}</th>
                {/foreach}
                <th>点击</th>
                <th>更新时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {foreach $contents as $v}
            <tr>
                <td>{$v.id}</td>
                <td>
                    {if !$v['status']}
                    <span class="label label-warning">未发布</span>
                    {/if}
                    {if $v['thumb']}
                    <span class="label label-danger">图</span>
                    {/if}
                    {if $v['jump']}
                    <span class="label label-info">跳转</span>
                    {/if}
                    <span>{$v.title?:''}</span>
                </td>
                <td>
                    {if $v['attr']}
                    {foreach $v['attr'] as $vo}
                    <span style="color: red;">[{$vo}]</span>
                    {/foreach}
                    {/if}
                </td>
                {foreach $fields as $field => $vo}
                <td>
                    {if isset($v[$field])}
                    {switch $vo['type']}
                        {case 'text'}
                        {$v[$field]?:''}
                        {/case}
                        {case 'textarea'}
                        {$v[$field]?:''}
                        {/case}
                        {case 'select'}
                        {$v[$field]?:''}
                        {/case}
                        {case 'checkbox'}
                        {$v[$field]?implode($v[$field], ','):''}
                        {/case}
                        {case 'upload'}
                            {php}
                                $ext = pathinfo($v[$field], PATHINFO_EXTENSION);
                            {/php}
                            {switch $ext}
                                {case 'jpg'}
                                {case 'jpeg'}
                                {case 'png'}
                                {case 'gif'}
                                <a href="{:real_url($v[$field]?:'')}" target="_blank"><img src="{:real_url($v[$field]?:'')}" width="30" height="30" alt=""></a>
                                {/case}
                                {default}
                                {$ext}
                                {/default}
                            {/switch}
                        {/case}
                        {case 'uploads'}
                            {if is_array($v[$field])}
                            {foreach $v[$field] as $voo}
                                {php}
                                    $ext = pathinfo($voo, PATHINFO_EXTENSION);
                                {/php}
                                {switch $ext}
                                    {case 'jpg'}
                                    {case 'jpeg'}
                                    {case 'png'}
                                    {case 'gif'}
                                    <a href="{:real_url($voo?:'')}" target="_blank"><img src="{:real_url($voo?:'')}" width="30" height="30" alt=""></a>
                                    {/case}
                                    {default}
                                    {$ext}
                                    {/default}
                                {/switch}
                            {/foreach}
                            {/if}
                        {/case}
                        {case 'editor'}
                        {$v[$field]?htmlspecialchars_decode($v[$field]):''}
                        {/case}
                    {/switch}
                    {/if}
                </td>
                {/foreach}
                <td>{$v.click?:''}</td>
                <td>{:date('Y-m-d H:i:s', $v['update_time'])}</td>
                <td>
                    <a href="{:\mylib\Route::buildUrl('/admin/content/edit')}?id={$v.id}">编辑</a>
                    <a href="#" onclick="M.del('{$v.id}')">删除</a>
                </td>
            </tr>
            {/foreach}
        </tbody>
    </table>
</div>
<nav>
    <ul class="pagination">
        {foreach $pages as $v}
            {if isset($v['disable'])}
                <li class="disabled"><a href="javascript:void(0);">{$v.text}</a></li>
            {elseif isset($v['current'])}
                <li class="active"><a href="javascript:void(0);">{$v.text}</a></li>
            {else}
                <li><a href="{:url('/admin/content/index')}?channel_id={$channel.id}&page={$v.page}">{$v.text}</a></li>
            {/if}
        {/foreach}
    </ul>
</nav>
{include /common/footer}